package com.lyh.order.server.impl;

import com.lyh.domain.bean.OrderInfo;
import com.lyh.domain.server.OrderService;
import com.lyh.domain.server.StockInfoServer;
import com.lyh.dt.annotation.GroupTransaction;
import com.lyh.order.dao.OrderInfoMapper;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author liuyuhong
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private  OrderInfoMapper mapper;

    @DubboReference
    private StockInfoServer stockInfoServer;

    @Override
    @Transactional
    @GroupTransaction
    public void insertOrder(OrderInfo orderInfo) {
        mapper.insertOrder(orderInfo);
        try {
            stockInfoServer.subStockByGoodsId(orderInfo.getGoodsId(), orderInfo.getCount());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
